/*
  Copyright � 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  ThanhNam ERP Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using VINETLIFE.DO;
/// <summary>
/// Summary description for cmsContactDAL
/// </summary>
namespace VINETLIFE.DAL 
{
    
    public class cmsContactDAL  : BaseDAL
    {
    	#region Private Variables
			
		#endregion
		
		#region Public Constructors
				public cmsContactDAL()
				{
					//
					// TODO: Add constructor logic here
					//
					
				}
		#endregion       

	
		
		#region Public Methods
        public int Insert(cmsContactDO objcmsContactDO)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsContact_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Title", SqlDbType.NVarChar);
Sqlparam.Value = objcmsContactDO.Title;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Name", SqlDbType.NVarChar);
Sqlparam.Value = objcmsContactDO.Name;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Address", SqlDbType.NVarChar);
Sqlparam.Value = objcmsContactDO.Address;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Email", SqlDbType.NVarChar);
Sqlparam.Value = objcmsContactDO.Email;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Phone", SqlDbType.NVarChar);
Sqlparam.Value = objcmsContactDO.Phone;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Description", SqlDbType.NVarChar);
Sqlparam.Value = objcmsContactDO.Description;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@UserId", SqlDbType.Int);
Sqlparam.Value = objcmsContactDO.UserId;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
Sqlparam.Value = objcmsContactDO.CreatedDate;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@IsRead", SqlDbType.Bit);
Sqlparam.Value = objcmsContactDO.IsRead;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@FirstUserIdRead", SqlDbType.Int);
Sqlparam.Value = objcmsContactDO.FirstUserIdRead;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@StatusId", SqlDbType.VarChar);
Sqlparam.Value = objcmsContactDO.StatusId;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
Sqlparam.Direction = ParameterDirection.ReturnValue;
Sqlcomm.Parameters.Add(Sqlparam);

           
            int result =base.ExecuteNoneQuery(Sqlcomm);
            
            if(!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
				result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsContactDO objcmsContactDO)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsContact_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ContactId", SqlDbType.Int);
Sqlparam.Value = objcmsContactDO.ContactId;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Title", SqlDbType.NVarChar);
Sqlparam.Value = objcmsContactDO.Title;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Name", SqlDbType.NVarChar);
Sqlparam.Value = objcmsContactDO.Name;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Address", SqlDbType.NVarChar);
Sqlparam.Value = objcmsContactDO.Address;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Email", SqlDbType.NVarChar);
Sqlparam.Value = objcmsContactDO.Email;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Phone", SqlDbType.NVarChar);
Sqlparam.Value = objcmsContactDO.Phone;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Description", SqlDbType.NVarChar);
Sqlparam.Value = objcmsContactDO.Description;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@UserId", SqlDbType.Int);
Sqlparam.Value = objcmsContactDO.UserId;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
Sqlparam.Value = objcmsContactDO.CreatedDate;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@IsRead", SqlDbType.Bit);
Sqlparam.Value = objcmsContactDO.IsRead;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@FirstUserIdRead", SqlDbType.Int);
Sqlparam.Value = objcmsContactDO.FirstUserIdRead;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@StatusId", SqlDbType.VarChar);
Sqlparam.Value = objcmsContactDO.StatusId;
Sqlcomm.Parameters.Add(Sqlparam);


            
            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);
            
            int result=base.ExecuteNoneQuery(Sqlcomm);
            
             if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);
                
            return result;

           
        }

        public int Delete(cmsContactDO objcmsContactDO)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsContact_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ContactId", SqlDbType.Int);
Sqlparam.Value = objcmsContactDO.ContactId;
Sqlcomm.Parameters.Add(Sqlparam);


            
            int result=base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

         public int DeleteAll()
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsContact_DeleteAll";

            int result=base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsContactDO Select(cmsContactDO objcmsContactDO)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsContact_GetByPK";
            SqlParameter Sqlparam;
  

            Sqlparam = new SqlParameter("@ContactId", SqlDbType.Int);
Sqlparam.Value = objcmsContactDO.ContactId;
Sqlcomm.Parameters.Add(Sqlparam);


            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if(!Convert.IsDBNull(dr["ContactId"]))
objcmsContactDO.ContactId=Convert.ToInt32(dr["ContactId"]);
if(!Convert.IsDBNull(dr["Title"]))
objcmsContactDO.Title=Convert.ToString(dr["Title"]);
if(!Convert.IsDBNull(dr["Name"]))
objcmsContactDO.Name=Convert.ToString(dr["Name"]);
if(!Convert.IsDBNull(dr["Address"]))
objcmsContactDO.Address=Convert.ToString(dr["Address"]);
if(!Convert.IsDBNull(dr["Email"]))
objcmsContactDO.Email=Convert.ToString(dr["Email"]);
if(!Convert.IsDBNull(dr["Phone"]))
objcmsContactDO.Phone=Convert.ToString(dr["Phone"]);
if(!Convert.IsDBNull(dr["Description"]))
objcmsContactDO.Description=Convert.ToString(dr["Description"]);
if(!Convert.IsDBNull(dr["UserId"]))
objcmsContactDO.UserId=Convert.ToInt32(dr["UserId"]);
if(!Convert.IsDBNull(dr["CreatedDate"]))
objcmsContactDO.CreatedDate=Convert.ToDateTime(dr["CreatedDate"]);
if(!Convert.IsDBNull(dr["IsRead"]))
objcmsContactDO.IsRead=Convert.ToBoolean(dr["IsRead"]);
if(!Convert.IsDBNull(dr["FirstUserIdRead"]))
objcmsContactDO.FirstUserIdRead=Convert.ToInt32(dr["FirstUserIdRead"]);
if(!Convert.IsDBNull(dr["StatusId"]))
objcmsContactDO.StatusId=Convert.ToString(dr["StatusId"]);

            }
             return objcmsContactDO;
        }

        public ArrayList SelectAll1( )
        {
			
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsContact_GetAll";
            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsContactDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach(DataRow dr in dt.Rows)
{
cmsContactDO objcmsContactDO= new cmsContactDO();
if(!Convert.IsDBNull(dr["ContactId"]))
objcmsContactDO.ContactId=Convert.ToInt32(dr["ContactId"]);
if(!Convert.IsDBNull(dr["Title"]))
objcmsContactDO.Title=Convert.ToString(dr["Title"]);
if(!Convert.IsDBNull(dr["Name"]))
objcmsContactDO.Name=Convert.ToString(dr["Name"]);
if(!Convert.IsDBNull(dr["Address"]))
objcmsContactDO.Address=Convert.ToString(dr["Address"]);
if(!Convert.IsDBNull(dr["Email"]))
objcmsContactDO.Email=Convert.ToString(dr["Email"]);
if(!Convert.IsDBNull(dr["Phone"]))
objcmsContactDO.Phone=Convert.ToString(dr["Phone"]);
if(!Convert.IsDBNull(dr["Description"]))
objcmsContactDO.Description=Convert.ToString(dr["Description"]);
if(!Convert.IsDBNull(dr["UserId"]))
objcmsContactDO.UserId=Convert.ToInt32(dr["UserId"]);
if(!Convert.IsDBNull(dr["CreatedDate"]))
objcmsContactDO.CreatedDate=Convert.ToDateTime(dr["CreatedDate"]);
if(!Convert.IsDBNull(dr["IsRead"]))
objcmsContactDO.IsRead=Convert.ToBoolean(dr["IsRead"]);
if(!Convert.IsDBNull(dr["FirstUserIdRead"]))
objcmsContactDO.FirstUserIdRead=Convert.ToInt32(dr["FirstUserIdRead"]);
if(!Convert.IsDBNull(dr["StatusId"]))
objcmsContactDO.StatusId=Convert.ToString(dr["StatusId"]);
arrcmsContactDO.Add(objcmsContactDO);
}
            }
               return arrcmsContactDO;
        }
        
        public DataTable SelectAll( )
        {
			
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsContact_GetAll";
            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
          
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                
            }
               return dt;
        }

     
		#endregion          
    
    }

}
